<include file="Public:_header" />
<div class="main">
    <div>
	  <style>
	   .tyh tr td{ text-align:center;}  
	  </style>
	  <notempty name='shop'>
	  <form action="{:U('Index/goods_order')}" method="post">
	  <table align="center" width="800px" class="tyh" style=" margin:0px auto;">
	        <tr><td colspan="7" ><div style="text-align:left; background:#CCCCCC; height:25px; line-height:25px;">&nbsp;&nbsp;&nbsp;&nbsp;购物车</div></td></tr>
			<tr><td>选择</td><td>图像</td><td>名称</td><td>单价</td><td>数量</td><td>价格</td><td>操作</td></tr>
	     <volist name='shop' id='shops'>
	        <tr bgcolor="#CC9966">
			   <td width="100px"><input name="check[]" class="shopcheck" type="checkbox" value="{$shops.go_id}" checked /></td>
			   <td><img src="{:getalbumface($shops['go_pics'])}"  width="30px" height="30px"/></td>
			   <td>{$shops['go_name']}</td>
			   <td class="danjia">{$shops['go_value']}</td>
			   <td>
			      <input type="text" class="ajaxnum" name="number[]" value="{$shops['shop_num']}"  style="width:40px; text-align:center;"/>
				  <input type="hidden" class="ajaxid" value="{$shops.id}" />  
				</td>
			   <td class="shopvalue">{$shops['go_value']*$shops['shop_num']}</td>
			   <td><div class="shopdel" style="color:#FF0000; font-size:20px; cursor:pointer;">x</div></td>
			 </tr>  
	     </volist>
			 <tr><td colspan="7" bgcolor="#999999" height="30px">
			        <div   style="float:left;">&nbsp;&nbsp;&nbsp;已选商品<font class="shopnum" style="color:#FF3300; font-weight:bold; font-size:20px;"></font>件</div>
					<div style="float:left; cursor:pointer;" class="clearshop">清空购物车</div>
					<div style=" float:right;"><input type="submit" value="去结算" style="float:right; width:100px; height:30px; background:#FF0000; color:#FFFFFF; line-height:30px; border:0px; cursor:pointer;" /></div>
					<div  style="float:right;">总价（不包含运费）<font class="shoptotal" style="color:#FF3300; font-weight:bold; font-size:20px;"></font>元&nbsp;&nbsp;&nbsp;</div>
			 </td></tr>
	  </table>
	</form>
	<else />
	<!-- 购物车为空 -->
	<div class="emptycart">
		 <div class="emptycart_bg fl"></div>
		 <div class="fl emptycart_text">
			 购物车空空的哦~，去看看心仪的商品吧~
			 <br/><a class="colorred" href="{:U('index')}">去购物></a>
		 </div>
	</div>
	</notempty>
	</div>
</div>
<div class="xiakeappend"></div>
<div class="clear"></div>
<include file="Public:_footer" />
<literal>
<script>
$(document).ready(function(){
   var shopnum=$(".shopcheck").length;//购物车内商品数量
	  var $subtotal=0;
	  for(var $i=0;$i<shopnum;$i++){
	     $subtotal=$subtotal+parseInt($(".shopcheck").parent().parent().eq($i).find(".shopvalue").text());
	  }
	  $(".shopnum").text(shopnum);
      $(".shoptotal").text($subtotal);
	  var  shengyuvalue=$subtotal;
        $(".shopcheck").change(function(){  //去掉多选框后
            var shopnum=$(".shopcheck:checked").length;//购物车内商品数量
		    $(".shopnum").text(shopnum);
			var changevaue=$(this).parent().parent().find(".shopvalue").text()
			 
			 if($(this).is(":checked")){
			     shengyuvalue=shengyuvalue+parseInt(changevaue);
			     $(this).parent().parent().find(".ajaxnum").attr('name',"number[]");
			 }else{
			 	 shengyuvalue=shengyuvalue-parseInt(changevaue);
			 	 $(this).parent().parent().find(".ajaxnum").attr('name',"");
			 }
			$(".shoptotal").text(shengyuvalue);
	    });
		
		
		$(".shopdel").click(function(){                                   //删除购物车内一件商品
		  var $ajaxnum=$(this).parent().parent().find(".ajaxnum").val();
		  var $ajaxid=$(this).parent().parent().find(".ajaxid").val();
		  var jianvalue=$(this).parent().parent().find(".shopvalue").text() 
		      $.post("http://localhost/shop/index.php/Index/shopajax",{action:"del",id:$ajaxid});
			  $(this).parent().parent().remove();
			  $(".shoptotal").text(parseInt($(".shoptotal").text())-parseInt(jianvalue));
		});
		
		$(".ajaxnum").change(function(){
		  var $ajaxnum=$(this).parent().parent().find(".ajaxnum").val();
		  var $ajaxid=$(this).parent().parent().find(".ajaxid").val();
          var shopnum=$(".shopcheck:checked").length;//购物车内商品数量
		      $subtotal=0;
		   $.post("http://localhost/shop/index.php/Index/shopajax",{action:"editnum",id:$ajaxid,num:$(this).val()});
		   $(this).parent().parent().find(".shopvalue").text($(this).parent().parent().find(".danjia").text()*$ajaxnum);
		   	  for(var $i=0;$i<shopnum;$i++){
	              $subtotal=$subtotal+parseInt($(".shopcheck").parent().parent().eq($i).find(".shopvalue").text());
	          }
		   $(".shoptotal").text($subtotal);
		});
		
		$(".clearshop").click(function(){                 //清空购物车
		  var $ajaxid=$(this).parent().parent().find(".ajaxid").val();
		     $.post("http://localhost/shop/index.php/Index/shopajax",{action:"clear",id:$ajaxid});
		});

});
</script>
</literal>
</body>
</html>
